//
//  UIBarButtonItem+extension.swift
//  MySinaWeiBoSwiftProject
//
//  Created by apple on 2016/11/12.
//  Copyright © 2016年 WangChen. All rights reserved.
//

import UIKit


extension UIBarButtonItem{
    
    convenience init(title: String = "",imageName: String? = nil,target: Any?, action: Selector?) {
        
        let btn = UIButton()
        
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(#colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1), for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        
        if let im = imageName {
            btn.setImage(UIImage(named: im), for:.normal)
            btn.setImage(UIImage(named: im + "_highlighted"), for: .highlighted)
        }
        
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 20)
        
        if let ac = action{
            
            btn.addTarget(target, action: ac, for:.touchUpInside)
        }
        
        btn.sizeToFit()
        self.init()
        
        customView = btn
    }
    
    
}
